
public class ComplexSet 
{
	private final Complex[] elements;
	private int size;
	private final double precision;
	private final static int MAX_SIZE =100;
	
	public ComplexSet()
	{
		this(2.0d * Double.MIN_VALUE);
	}
	
	public ComplexSet(Double precision)
	{
		this.size = 0;
		this.elements = new Complex[MAX_SIZE];
		this.precision=precision;
	}
	
	public boolean contains(Complex element)
	{
		for (int i=0; i < this.size; i++)
		{
			if (elements[i].approximatelyEquals(element, this.precision))
			{
				return true;
			}
		}
		return false;
	}
	
	public void add(Complex element) throws Exception
	{
		if (this.contains(element))
			return;
		if (this.size < ComplexSet.MAX_SIZE)
		{
			this.elements[size] = element;
			this.size++;
		}
		else
		{
			throw new Exception("Set if full");
		}
	}
	
	public void remove(Complex element)
	{
		int pos = find(element);
		
		if (pos >= 0)
		{
			for(int i = pos + 1; i < this.size -1 ; i++)
				elements[i] = elements[i+1];
				this.size = this.size - 1;
		}
	}
	
	private int find (Complex element)
	{
		for(int i=0; i < this.size; i++)
		{
			if(elements[i].approximatelyEquals(element, this.precision))
			{
				return i;
			}
		}
		return -1;
	}
	
	
}
